home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / MALLOC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  415 b   |  18 lines

  1. /* malloc.c --- p. 137 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <alloc.h>
  5. #define MAX_CHR 80
  6. main()
  7. {
  8.     char *buffer;
  9.         /*  Allocate room for string and check for NULL pointer */
  10.     if( (buffer = (char *)malloc(MAX_CHR)) == NULL)
  11.     {
  12.         printf("Allocation Failed.\n");
  13.         exit(0);
  14.     }
  15.     printf("Buffer allocated. Enter string to store: ");
  16.     gets(buffer);
  17.     printf("\nYou entered: %s\n",buffer);
  18. }